{extend name="template/base" /}
{block name="content"}
{php}use think\Db;{/php}
<div class="page-container">
    <!--{include file="form" /}-->
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            {tp:menu menu="add" /}
        </span>
        <!--<span class="r pt-5 pr-5">-->
            <!--共有数据 ：<strong>{$count ?? '0'}</strong> 条-->
        <!--</span>-->
    </div>
    <div class="layui-tab" lay-filter="demo">
        <ul class="layui-tab-title">
            <li class="layui-this">未处理</li>
            <li>已处理</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                {volist id="vo" name="list"}
                <table class="table table-border table-bordered table-hover table-bg mt-20">
                    <thead>
                    <th colspan="2">创建时间:{$vo.create_time|date="Y-m-d H:i:s",###}</th>
                    </thead>
                    <tbody>
                    <tr>
                        <td width="65%">
                            <div>
                                <p>发送内容:</p>
                                <p>{$vo.content}</p>
                            </div>

                        </td>
                        <td width="35%">
                            <div>
                                {if !empty($vo['supplement_data'])}
                                    <div>
                                        <p>暂无信息</p>
                                    </div>
                                {/if}
                                 <p>发送人:
                                     {php}
                                         echo Db::name('admin_user_info')->where('id',$vo['from_account'])->value('realname');
                                     {/php}
                                 </p>
                                 <p>部门:
                                     {php}
                                         if($vo['from_department'] == 0){
                                            echo "超级管理员";
                                         }else{
                                            echo Db::name('admin_role')->where('id',$vo['from_department'])->value('name');
                                         }
                                     {/php}
                                 </p>
                            </div>

                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            {php}
                                if($vo['is_from'] == 1 && $vo['is_check']){
                                    $department = Db::name('system_notification')->where('parent_id',$vo['id'])->field('id,send_department,status')->select();
                                    echo "<p class='l'>部门：";
                                    foreach($department as $dk => $dv){
                                        echo "<span>";
                                        $role = Db::name('admin_role')
                                             ->where('id',$dv['send_department'])
                                             ->value('name');
                                        if($dv['status'] == 'unfinished'){
                                            $status = '未处理';
                                        }else{
                                            $status = '已处理';
                                        }
                                        echo $role."(".$status.")&nbsp;&nbsp;";
                                        echo "</span>";
                                    }
                                    echo "</p>";
                                }
                            {/php}
                            {if $vo['status'] == 'unfinished'}
                                <input type="button" class="r btn btn-primary" value="处理完成" onclick="finished('{$vo.id}')">
                            {else/}
                                <input type="button" class="r btn btn-danger" onclick="del('{$v.id}')" value="删除">
                                <input type="button" class="r btn btn-default" value="已处理">
                            {/if}
                        </td>
                    </tr>
                    </tbody>
                </table>
                {/volist}
            </div>
            <div class="layui-tab-item">
                {volist id="v" name="list_finish"}
                <table class="table table-border table-bordered table-hover table-bg mt-20">
                    <thead>
                    <th colspan="2">创建时间:{$v.create_time|date="Y-m-d H:i:s",###}</th>
                    </thead>
                    <tbody>
                    <tr>
                        <td width="65%">
                            <div>
                                <p>发送内容:</p>
                                <p>{$v.content}</p>
                            </div>

                        </td>
                        <td width="35%">
                            <div>
                                {if !empty($v['supplement_data'])}
                                    <div>
                                        <div>
                                            <p>暂无信息</p>
                                        </div>
                                    </div>
                                {/if}
                                <p>发送人:
                                    {php}
                                        echo Db::name('admin_user_info')->where('id',$v['from_account'])->value('realname');
                                    {/php}
                                </p>
                                <p>部门:
                                    {php}
                                        if($v['from_department'] == 0){
                                        echo "超级管理员";
                                    }else{
                                        echo Db::name('admin_role')->where('id',$v['from_department'])->value('name');
                                    }
                                    {/php}
                                </p>
                            </div>

                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            {php}
                                if($v['is_from'] == 1 && $v['is_check']){
                                    $department = Db::name('system_notification')->where('parent_id',$v['id'])->field('id,send_department,status')->select();
                                    echo "<p class='l'>部门：";
                                    foreach($department as $dk => $dv){
                                        echo "<span>";
                                        $role = Db::name('admin_role')
                                             ->where('id',$dv['send_department'])
                                             ->value('name');
                                        if($dv['status'] == 'unfinished'){
                                            $status = '未处理';
                                        }else{
                                            $status = '已处理';
                                        }
                                        echo $role."(".$status.")&nbsp;&nbsp;";
                                        echo "</span>";
                                    }
                                    echo "</p>";
                                }
                            {/php}
                            {if $v['status'] == 'unfinished'}
                                <input type="button" class="r btn btn-primary" value="处理完成" onclick="finished('{$v.id}')">
                            {else/}
                                <input type="button" class="r btn btn-danger" onclick="del('{$v.id}')" value="删除">
                                <input type="button" class="r btn btn-default" value="已处理">
                            {/if}
                        </td>
                    </tr>
                    </tbody>
                </table>
                {/volist}
            </div>
        </div>
    </div>


    <!--<div class="page-bootstrap">{$page ?? ''}</div>-->
</div>
{/block}
{block name="script"}
<script src="__STATIC__/layui-xia/layui.js"></script>
<script>
    function del(id) {
        layer.confirm("确定删除记录？", {
            btn: ['确定', '取消'],
            title: '提示',
            icon: 3
        }, function () {
            $.ajax({
                type: 'post',
                url: '/admin/system_notification/delete',
                data: {id:id},
                success: function (res) {
                    if (res.code == 0){
                        layer.msg(res.msg, {
                            time: 2000 //2秒关闭
                        }, function () {
                            window.location.reload(); //刷新父页面
                        });
                        console.log('data', res);
                    } else {
                        layer.msg(res.msg, {
                            time: 2000 //2秒关闭
                        }, function () {
                            window.location.reload(); //刷新父页面
                        });
                    }
                    console.log('data', 555);
                }
            });
        });
    }
    function finished(id) {
        $.ajax({
            type: 'post',
            url: '/admin/system_notification/finished',
            data: {id:id},
            success: function (res) {
                console.log('data', 123);
                console.log('res', res);
                if (res.code == 0){
                    layer.msg(res.msg, {
                        time: 2000 //2秒关闭
                    }, function () {
                        window.location.reload(); //刷新父页面
                    });
                     console.log('data', res);
                } else {
                    layer.msg(res.msg, {
                        time: 2000 //2秒关闭
                    }, function () {
                        window.location.reload(); //刷新父页面
                    });
                }
                console.log('data', 555);
            }
        });
    }
    layui.use('element', function(){
        var element = layui.element;

        //一些事件监听
        element.on('tab(demo)', function(data){
            console.log(data);
        });
    });
</script>

{/block}

